/*      */ package com.zimbra.qa.unittest;
/*      */ 
/*      */ import com.google.common.base.Strings;
/*      */ import com.zimbra.client.ZEmailAddress;
/*      */ import com.zimbra.client.ZFilterAction;
/*      */ import com.zimbra.client.ZFilterAction.MarkOp;
/*      */ import com.zimbra.client.ZFilterAction.ZDiscardAction;
/*      */ import com.zimbra.client.ZFilterAction.ZFileIntoAction;
/*      */ import com.zimbra.client.ZFilterAction.ZKeepAction;
/*      */ import com.zimbra.client.ZFilterAction.ZMarkAction;
/*      */ import com.zimbra.client.ZFilterAction.ZNotifyAction;
/*      */ import com.zimbra.client.ZFilterAction.ZRedirectAction;
/*      */ import com.zimbra.client.ZFilterAction.ZReplyAction;
/*      */ import com.zimbra.client.ZFilterAction.ZTagAction;
/*      */ import com.zimbra.client.ZFilterCondition;
/*      */ import com.zimbra.client.ZFilterCondition.BodyOp;
/*      */ import com.zimbra.client.ZFilterCondition.DateOp;
/*      */ import com.zimbra.client.ZFilterCondition.HeaderOp;
/*      */ import com.zimbra.client.ZFilterCondition.SimpleOp;
/*      */ import com.zimbra.client.ZFilterCondition.ZAddressCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZAttachmentExistsCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZBodyCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZCurrentDayOfWeekCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZCurrentTimeCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZDateCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZHeaderCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZInviteCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZMimeHeaderCondition;
/*      */ import com.zimbra.client.ZFilterCondition.ZTrueCondition;
/*      */ import com.zimbra.client.ZFilterRule;
/*      */ import com.zimbra.client.ZFilterRules;
/*      */ import com.zimbra.client.ZFolder;
/*      */ import com.zimbra.client.ZItem.Flag;
/*      */ import com.zimbra.client.ZMailbox;
/*      */ import com.zimbra.client.ZMailbox.ReplyVerb;
/*      */ import com.zimbra.client.ZMailbox.ZOutgoingMessage;
/*      */ import com.zimbra.client.ZMessage;
/*      */ import com.zimbra.client.ZMessage.ZMimePart;
/*      */ import com.zimbra.client.ZTag;
/*      */ import com.zimbra.common.filter.Sieve.AddressPart;
/*      */ import com.zimbra.common.mime.MimeMessage;
/*      */ import com.zimbra.common.service.ServiceException;
/*      */ import com.zimbra.common.soap.SoapFaultException;
/*      */ import com.zimbra.common.util.ByteUtil;
/*      */ import com.zimbra.common.util.StringUtil;
/*      */ import com.zimbra.cs.account.Account;
/*      */ import com.zimbra.cs.account.Config;
/*      */ import com.zimbra.cs.account.Provisioning;
/*      */ import com.zimbra.cs.account.Server;
/*      */ import com.zimbra.cs.filter.FilterUtil;
/*      */ import com.zimbra.cs.filter.RuleManager;
/*      */ import com.zimbra.cs.filter.RuleRewriter;
/*      */ import com.zimbra.cs.filter.SieveToSoap;
/*      */ import com.zimbra.cs.filter.SoapToSieve;
/*      */ import com.zimbra.cs.mailbox.calendar.Util;
/*      */ import java.io.BufferedReader;
/*      */ import java.io.ByteArrayInputStream;
/*      */ import java.io.File;
/*      */ import java.io.IOException;
/*      */ import java.io.StringReader;
/*      */ import java.text.SimpleDateFormat;
/*      */ import java.util.ArrayList;
/*      */ import java.util.Arrays;
/*      */ import java.util.Calendar;
/*      */ import java.util.Date;
/*      */ import java.util.HashSet;
/*      */ import java.util.LinkedList;
/*      */ import java.util.List;
/*      */ import java.util.Set;
/*      */ import java.util.TimeZone;
/*      */ import junit.framework.TestCase;
/*      */ import org.apache.jsieve.SieveFactory;
/*      */ import org.apache.jsieve.parser.generated.Node;
/*      */ import org.apache.jsieve.parser.generated.ParseException;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public final class TestFilter
/*      */   extends TestCase
/*      */ {
/*   90 */   private static String USER_NAME = "user1";
/*   91 */   private static String REMOTE_USER_NAME = "user2";
/*   92 */   private static String NAME_PREFIX = "TestFilter";
/*   93 */   private static String FOLDER1_NAME = NAME_PREFIX + "-folder1";
/*   94 */   private static String FOLDER2_NAME = NAME_PREFIX + "-folder2";
/*   95 */   private static String FOLDER1_PATH = "/" + FOLDER1_NAME;
/*   96 */   private static String FOLDER2_PATH = "/" + FOLDER2_NAME;
/*   97 */   private static String TAG1_NAME = NAME_PREFIX + "-tag1";
/*   98 */   private static String TAG2_NAME = NAME_PREFIX + "-tag2";
/*   99 */   private static String MOUNTPOINT_FOLDER_NAME = NAME_PREFIX + " mountpoint";
/*  100 */   private static String MOUNTPOINT_SUBFOLDER_NAME = NAME_PREFIX + " mountpoint subfolder";
/*  101 */   private static String MOUNTPOINT_SUBFOLDER_PATH = "/" + MOUNTPOINT_FOLDER_NAME + "/" + MOUNTPOINT_SUBFOLDER_NAME;
/*      */   
/*      */   private ZMailbox mMbox;
/*      */   private ZFilterRules mOriginalIncomingRules;
/*      */   private ZFilterRules mOriginalOutgoingRules;
/*      */   private String mOriginalSpamApplyUserFilters;
/*  107 */   private String mOriginalSmtpPort = null;
/*  108 */   private String mOriginalSetEnvelopeSender = null;
/*      */   private ZTag mTag1;
/*      */   private ZTag mTag2;
/*      */   
/*      */   public void setUp() throws Exception
/*      */   {
/*  114 */     cleanUp();
/*      */     
/*  116 */     this.mMbox = TestUtil.getZMailbox(USER_NAME);
/*  117 */     this.mTag1 = this.mMbox.createTag(TAG1_NAME, null);
/*  118 */     this.mTag2 = this.mMbox.createTag(TAG2_NAME, null);
/*      */     
/*      */ 
/*  121 */     ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
/*  122 */     TestUtil.createMountpoint(remoteMbox, "/" + MOUNTPOINT_FOLDER_NAME, this.mMbox, MOUNTPOINT_FOLDER_NAME);
/*  123 */     TestUtil.createFolder(remoteMbox, MOUNTPOINT_SUBFOLDER_PATH);
/*      */     
/*  125 */     this.mOriginalIncomingRules = this.mMbox.getIncomingFilterRules();
/*  126 */     saveIncomingRules(this.mMbox, getTestIncomingRules());
/*  127 */     this.mOriginalOutgoingRules = this.mMbox.getOutgoingFilterRules();
/*  128 */     saveOutgoingRules(this.mMbox, getTestOutgoingRules());
/*      */     
/*  130 */     Account account = TestUtil.getAccount(USER_NAME);
/*  131 */     this.mOriginalSpamApplyUserFilters = account.getAttr("zimbraSpamApplyUserFilters");
/*  132 */     this.mOriginalSmtpPort = Provisioning.getInstance().getLocalServer().getSmtpPortAsString();
/*  133 */     this.mOriginalSetEnvelopeSender = TestUtil.getServerAttr("zimbraMailRedirectSetEnvelopeSender");
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testOutgoingFiltersWithSendMsg()
/*      */     throws Exception
/*      */   {
/*  141 */     String sender = TestUtil.getAddress(USER_NAME);
/*  142 */     String recipient = TestUtil.getAddress(REMOTE_USER_NAME);
/*  143 */     String subject = NAME_PREFIX + " outgoing";
/*      */     
/*  145 */     List<ZEmailAddress> addrs = new LinkedList();
/*  146 */     addrs.add(new ZEmailAddress(sender, null, null, "f"));
/*  147 */     addrs.add(new ZEmailAddress(recipient, null, null, "t"));
/*  148 */     ZMailbox.ZOutgoingMessage outgoingMsg = new ZMailbox.ZOutgoingMessage();
/*  149 */     outgoingMsg.setAddresses(addrs);
/*  150 */     outgoingMsg.setSubject(subject);
/*      */     
/*  152 */     this.mMbox.sendMessage(outgoingMsg, null, false);
/*      */     
/*      */ 
/*  155 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:" + FOLDER1_NAME + " " + subject);
/*  156 */     TestUtil.verifyTag(this.mMbox, msg, TAG1_NAME);
/*      */     
/*      */ 
/*  159 */     List<ZMessage> msgs = TestUtil.search(this.mMbox, "in:Sent " + subject);
/*  160 */     assertTrue(msgs.isEmpty());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testOutgoingFiltersWithAddMsg()
/*      */     throws Exception
/*      */   {
/*  168 */     String sender = TestUtil.getAddress(USER_NAME);
/*  169 */     String recipient = TestUtil.getAddress(REMOTE_USER_NAME);
/*  170 */     String subject = NAME_PREFIX + " outgoing";
/*  171 */     String content = new MessageBuilder().withSubject(subject).withFrom(sender).withToRecipient(recipient).create();
/*      */     
/*      */ 
/*  174 */     this.mMbox.addMessage("5", "s", null, System.currentTimeMillis(), content, false, true);
/*      */     
/*      */ 
/*  177 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:" + FOLDER1_NAME + " " + subject);
/*  178 */     TestUtil.verifyTag(this.mMbox, msg, TAG1_NAME);
/*      */     
/*      */ 
/*  181 */     List<ZMessage> msgs = TestUtil.search(this.mMbox, "in:Sent " + subject);
/*  182 */     assertTrue(msgs.isEmpty());
/*      */     
/*      */ 
/*  185 */     this.mMbox.addMessage("5", "s", null, System.currentTimeMillis(), content, false, false);
/*      */     
/*      */ 
/*  188 */     TestUtil.getMessage(this.mMbox, "in:Sent " + subject);
/*      */   }
/*      */   
/*      */   public void testQuoteEscape() throws Exception
/*      */   {
/*  193 */     List<ZFilterCondition> conditions = new ArrayList();
/*  194 */     List<ZFilterAction> actions = new ArrayList();
/*  195 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*  197 */     String folderName = NAME_PREFIX + " testQuoteEscape";
/*  198 */     TestUtil.createFolder(this.mMbox, folderName);
/*      */     
/*      */ 
/*  201 */     ZFilterCondition condition = new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "a \" b");
/*  202 */     ZFilterAction action = new ZFilterAction.ZFileIntoAction(folderName);
/*  203 */     conditions.add(condition);
/*  204 */     actions.add(action);
/*  205 */     rules.add(new ZFilterRule(folderName, true, false, conditions, actions));
/*      */     
/*  207 */     ZFilterRules zRules = new ZFilterRules(rules);
/*  208 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/*  211 */     String address = TestUtil.getAddress(USER_NAME);
/*  212 */     String subject = NAME_PREFIX + " a \" b y z";
/*  213 */     String searchSubject = NAME_PREFIX + " a b y z";
/*  214 */     TestUtil.addMessageLmtp(subject, address, address);
/*  215 */     TestUtil.getMessage(this.mMbox, "in:\"" + folderName + "\" subject:\"" + searchSubject + "\"");
/*      */   }
/*      */   
/*      */   public void testBackslashEscape() throws Exception
/*      */   {
/*  220 */     List<ZFilterCondition> conditions = new ArrayList();
/*  221 */     List<ZFilterAction> actions = new ArrayList();
/*  222 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*  224 */     String folderName = NAME_PREFIX + " testBackslashEscape";
/*  225 */     TestUtil.createFolder(this.mMbox, folderName);
/*      */     
/*      */ 
/*  228 */     ZFilterCondition condition = new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "a \\ b");
/*  229 */     ZFilterAction action = new ZFilterAction.ZFileIntoAction(folderName);
/*  230 */     conditions.add(condition);
/*  231 */     actions.add(action);
/*  232 */     rules.add(new ZFilterRule(folderName, true, false, conditions, actions));
/*      */     
/*  234 */     ZFilterRules zRules = new ZFilterRules(rules);
/*  235 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/*  238 */     String address = TestUtil.getAddress(USER_NAME);
/*  239 */     String subject = NAME_PREFIX + " a \\ b y z";
/*  240 */     TestUtil.addMessageLmtp(subject, address, address);
/*  241 */     TestUtil.getMessage(this.mMbox, "in:\"" + folderName + "\" subject:\"" + subject + "\"");
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testBase64Subject()
/*      */     throws Exception
/*      */   {
/*  251 */     List<ZFilterRule> rules = new ArrayList();
/*  252 */     List<ZFilterCondition> conditions = new ArrayList();
/*  253 */     List<ZFilterAction> actions = new ArrayList();
/*  254 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "Cortes de luz"));
/*  255 */     actions.add(new ZFilterAction.ZTagAction(TAG1_NAME));
/*  256 */     rules.add(new ZFilterRule("testBase64Subject", true, false, conditions, actions));
/*  257 */     ZFilterRules zRules = new ZFilterRules(rules);
/*  258 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*  260 */     String address = TestUtil.getAddress(USER_NAME);
/*  261 */     TestUtil.addMessageLmtp("=?UTF-8?B?W2l0dnNmLUluY2lkZW5jaWFzXVs0OTc3Ml0gW2luY2lkZW5jaWFzLXZpbGxhbnVldmFdIENvcnRlcyBkZSBsdXosIGTDrWEgMjUvMDkvMjAwNi4=?=", address, address);
/*      */     
/*      */ 
/*  264 */     List<ZMessage> messages = TestUtil.search(this.mMbox, "Cortes de luz");
/*  265 */     assertEquals("Unexpected number of messages", 1, messages.size());
/*  266 */     List<ZTag> tags = this.mMbox.getTags(((ZMessage)messages.get(0)).getTagIds());
/*  267 */     assertEquals("Unexpected number of tags", 1, tags.size());
/*  268 */     assertEquals("Tag didn't match", TAG1_NAME, ((ZTag)tags.get(0)).getName());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testMatchMultipleFilters()
/*      */     throws Exception
/*      */   {
/*  277 */     String sender = TestUtil.getAddress("multiplefilters");
/*  278 */     String recipient = TestUtil.getAddress(USER_NAME);
/*  279 */     String subject = NAME_PREFIX + " This goes into folder1 and folder2";
/*  280 */     TestUtil.addMessageLmtp(subject, recipient, sender);
/*      */     
/*  282 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:" + FOLDER1_PATH + " " + subject);
/*  283 */     TestUtil.verifyTag(this.mMbox, msg, TAG1_NAME);
/*  284 */     TestUtil.verifyTag(this.mMbox, msg, TAG2_NAME);
/*  285 */     TestUtil.verifyFlag(this.mMbox, msg, ZItem.Flag.flagged);
/*      */     
/*  287 */     msg = TestUtil.getMessage(this.mMbox, "in:" + FOLDER2_PATH + " " + subject);
/*  288 */     TestUtil.verifyTag(this.mMbox, msg, TAG1_NAME);
/*  289 */     TestUtil.verifyTag(this.mMbox, msg, TAG2_NAME);
/*  290 */     TestUtil.verifyFlag(this.mMbox, msg, ZItem.Flag.flagged);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testSpam()
/*      */     throws Exception
/*      */   {
/*  299 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/*  300 */     String sender = TestUtil.getAddress(USER_NAME);
/*  301 */     String[] recipients = { sender };
/*  302 */     String message = TestUtil.getTestMessage(NAME_PREFIX + " testSpam", USER_NAME, USER_NAME, null);
/*  303 */     Config config = Provisioning.getInstance().getConfig();
/*  304 */     message = config.getAttr("zimbraSpamHeader") + ": " + config.getAttr("zimbraSpamHeaderValue") + "\r\n" + message;
/*      */     
/*      */ 
/*      */ 
/*  308 */     assertEquals(0, TestUtil.search(mbox, "in:junk subject:testSpam").size());
/*      */     
/*      */ 
/*      */ 
/*  312 */     TestUtil.addMessageLmtp(recipients, sender, message);
/*  313 */     ZMessage msg = TestUtil.getMessage(mbox, "in:junk subject:testSpam");
/*  314 */     mbox.deleteMessage(msg.getId());
/*      */     
/*      */ 
/*  317 */     ZFilterRules rules = getTestIncomingRules();
/*  318 */     List<ZFilterCondition> conditions = new ArrayList();
/*  319 */     List<ZFilterAction> actions = new ArrayList();
/*  320 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "testSpam"));
/*  321 */     actions.add(new ZFilterAction.ZFileIntoAction(FOLDER1_PATH));
/*  322 */     rules.getRules().add(new ZFilterRule("testBug5455", true, false, conditions, actions));
/*  323 */     saveIncomingRules(this.mMbox, rules);
/*      */     
/*      */ 
/*  326 */     TestUtil.setAccountAttr(USER_NAME, "zimbraSpamApplyUserFilters", "TRUE");
/*  327 */     TestUtil.addMessageLmtp(recipients, sender, message);
/*  328 */     msg = TestUtil.waitForMessage(mbox, "in:" + FOLDER1_PATH + " subject:testSpam");
/*  329 */     mbox.deleteMessage(msg.getId());
/*      */     
/*      */ 
/*  332 */     TestUtil.setAccountAttr(USER_NAME, "zimbraSpamApplyUserFilters", "FALSE");
/*  333 */     TestUtil.addMessageLmtp(recipients, sender, message);
/*  334 */     TestUtil.waitForMessage(mbox, "in:junk subject:testSpam");
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testBug5455()
/*      */     throws Exception
/*      */   {
/*  343 */     String recipient = TestUtil.getAddress(USER_NAME);
/*  344 */     String subject = NAME_PREFIX + " Testing bug5455";
/*  345 */     TestUtil.addMessageLmtp(subject, recipient, recipient);
/*      */     
/*  347 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:" + FOLDER1_PATH + " " + subject);
/*  348 */     TestUtil.verifyFlag(this.mMbox, msg, ZItem.Flag.flagged);
/*  349 */     TestUtil.verifyTag(this.mMbox, msg, TAG1_NAME);
/*      */     
/*  351 */     msg = TestUtil.getMessage(this.mMbox, "in:" + FOLDER2_PATH + " " + subject);
/*  352 */     TestUtil.verifyFlag(this.mMbox, msg, ZItem.Flag.flagged);
/*  353 */     TestUtil.verifyTag(this.mMbox, msg, TAG1_NAME);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testDiscard()
/*      */     throws Exception
/*      */   {
/*  361 */     String recipient = TestUtil.getAddress(USER_NAME);
/*  362 */     String subject = NAME_PREFIX + " doDiscard";
/*  363 */     TestUtil.addMessageLmtp(subject, recipient, recipient);
/*  364 */     subject = NAME_PREFIX + " dontDiscard";
/*  365 */     TestUtil.addMessageLmtp(subject, recipient, recipient);
/*  366 */     TestUtil.waitForMessage(this.mMbox, "in:inbox dontDiscard");
/*  367 */     assertEquals(0, TestUtil.search(this.mMbox, "in:inbox doDiscard").size());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testMountpoint()
/*      */     throws Exception
/*      */   {
/*  375 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/*  376 */     String address = TestUtil.getAddress(USER_NAME);
/*  377 */     String subject = NAME_PREFIX + " mountpointRoot1";
/*  378 */     TestUtil.addMessageLmtp(subject, address, address);
/*      */     
/*      */ 
/*  381 */     TestUtil.waitForMessage(mbox, "in:\"/" + MOUNTPOINT_FOLDER_NAME + "\" subject:\"" + subject + "\"");
/*  382 */     assertEquals(0, TestUtil.search(mbox, "in:inbox subject:\"" + subject + "\"").size());
/*      */     
/*      */ 
/*  385 */     ZMailbox remote = TestUtil.getZMailbox(REMOTE_USER_NAME);
/*  386 */     ZFolder remoteFolder = remote.getFolderByPath("/" + MOUNTPOINT_FOLDER_NAME);
/*  387 */     remote.deleteFolder(remoteFolder.getId());
/*      */     
/*      */ 
/*  390 */     subject = NAME_PREFIX + " mountpointRoot2";
/*  391 */     TestUtil.addMessageLmtp(subject, address, address);
/*  392 */     TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/*  393 */     assertEquals(0, TestUtil.search(mbox, "in:\"/" + MOUNTPOINT_FOLDER_NAME + "\" subject:\"" + subject + "\"").size());
/*      */   }
/*      */   
/*      */   public void testMountpointSubfolder()
/*      */     throws Exception
/*      */   {
/*  399 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/*  400 */     String address = TestUtil.getAddress(USER_NAME);
/*  401 */     String subject = NAME_PREFIX + " mountpointSub1";
/*  402 */     TestUtil.addMessageLmtp(subject, address, address);
/*      */     
/*      */ 
/*  405 */     TestUtil.waitForMessage(mbox, "in:\"" + MOUNTPOINT_SUBFOLDER_PATH + "\" subject:\"" + subject + "\"");
/*  406 */     assertEquals(0, TestUtil.search(mbox, "in:inbox subject:\"" + subject + "\"").size());
/*      */     
/*      */ 
/*  409 */     ZMailbox remote = TestUtil.getZMailbox(REMOTE_USER_NAME);
/*  410 */     ZFolder remoteFolder = remote.getFolderByPath(MOUNTPOINT_SUBFOLDER_PATH);
/*  411 */     remote.deleteFolder(remoteFolder.getId());
/*      */     
/*      */ 
/*  414 */     subject = NAME_PREFIX + " mountpointSub2";
/*  415 */     TestUtil.addMessageLmtp(subject, address, address);
/*  416 */     TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/*  417 */     assertEquals(0, TestUtil.search(mbox, "in:\"" + MOUNTPOINT_SUBFOLDER_PATH + "\" subject:\"" + subject + "\"").size());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testConversion()
/*      */     throws Exception
/*      */   {
/*  427 */     String scriptPath = "/opt/zimbra/unittest/test.sieve";
/*  428 */     String script = new String(ByteUtil.getContent(new File(scriptPath)));
/*  429 */     assertNotNull(script);
/*  430 */     assertTrue(script.length() > 0);
/*  431 */     String convertedScript = normalize(script);
/*      */     
/*      */ 
/*  434 */     script = normalizeWhiteSpace(script);
/*  435 */     convertedScript = normalizeWhiteSpace(convertedScript);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  440 */     script = script.replace("fileInto", "fileinto");
/*  441 */     assertEquals(script, convertedScript);
/*      */   }
/*      */   
/*      */   public void testMimeHeader()
/*      */     throws Exception
/*      */   {
/*  447 */     String subject = NAME_PREFIX + " testMimeHeader";
/*  448 */     String attachmentData = "<html><body>I'm so attached to you.</body></html>";
/*  449 */     String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withAttachment(attachmentData, "attachment.html", "text/html").create();
/*      */     
/*      */ 
/*      */ 
/*  453 */     List<ZFilterRule> rules = new ArrayList();
/*  454 */     List<ZFilterCondition> conditions = new ArrayList();
/*  455 */     List<ZFilterAction> actions = new ArrayList();
/*      */     
/*  457 */     conditions.add(new ZFilterCondition.ZMimeHeaderCondition("Content-Type", ZFilterCondition.HeaderOp.CONTAINS, "text/plain"));
/*  458 */     actions.add(new ZFilterAction.ZTagAction(this.mTag1.getName()));
/*  459 */     rules.add(new ZFilterRule("testMarkRead 1", true, false, conditions, actions));
/*      */     
/*  461 */     conditions = new ArrayList();
/*  462 */     actions = new ArrayList();
/*  463 */     conditions.add(new ZFilterCondition.ZMimeHeaderCondition("Content-Type", ZFilterCondition.HeaderOp.CONTAINS, "text/html"));
/*  464 */     actions.add(new ZFilterAction.ZTagAction(this.mTag2.getName()));
/*  465 */     rules.add(new ZFilterRule("testMarkRead 2", true, false, conditions, actions));
/*      */     
/*  467 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*      */ 
/*  470 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
/*  471 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  472 */     Set<String> tagIds = new HashSet();
/*  473 */     tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
/*  474 */     assertEquals(2, tagIds.size());
/*  475 */     assertTrue(tagIds.contains(this.mTag1.getId()));
/*  476 */     assertTrue(tagIds.contains(this.mTag2.getId()));
/*      */   }
/*      */   
/*      */ 
/*      */   public void testToOrCc()
/*      */     throws Exception
/*      */   {
/*  483 */     List<ZFilterRule> rules = new ArrayList();
/*  484 */     List<ZFilterCondition> conditions = new ArrayList();
/*  485 */     List<ZFilterAction> actions = new ArrayList();
/*  486 */     conditions.add(new ZFilterCondition.ZHeaderCondition("to,cc", ZFilterCondition.HeaderOp.CONTAINS, "checkthis.com"));
/*  487 */     actions.add(new ZFilterAction.ZTagAction(this.mTag1.getName()));
/*  488 */     rules.add(new ZFilterRule("testToOrCc", true, false, conditions, actions));
/*  489 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*      */ 
/*  492 */     String subject = NAME_PREFIX + " testToOrCc 1";
/*  493 */     String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withCcRecipient("cc@checkthis.com").create();
/*  494 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
/*  495 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  496 */     Set<String> tagIds = new HashSet();
/*  497 */     assertNotNull(msg.getTagIds());
/*  498 */     tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
/*  499 */     assertEquals(1, tagIds.size());
/*  500 */     assertTrue(tagIds.contains(this.mTag1.getId()));
/*      */     
/*      */ 
/*  503 */     subject = NAME_PREFIX + " testToOrCc 2";
/*  504 */     content = new MessageBuilder().withSubject(subject).withToRecipient("to@checkthis.com").withCcRecipient(USER_NAME).create();
/*  505 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
/*  506 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  507 */     tagIds = new HashSet();
/*  508 */     assertNotNull(msg.getTagIds());
/*  509 */     tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
/*  510 */     assertEquals(1, tagIds.size());
/*  511 */     assertTrue(tagIds.contains(this.mTag1.getId()));
/*      */   }
/*      */   
/*      */ 
/*      */   public void testCaseSensitiveComparison()
/*      */     throws Exception
/*      */   {
/*  518 */     List<ZFilterRule> rules = new ArrayList();
/*  519 */     List<ZFilterCondition> conditions = new ArrayList();
/*  520 */     List<ZFilterAction> actions = new ArrayList();
/*  521 */     conditions.add(new ZFilterCondition.ZHeaderCondition("Subject", ZFilterCondition.HeaderOp.CONTAINS, true, "CHECK THIS"));
/*  522 */     conditions.add(new ZFilterCondition.ZBodyCondition(ZFilterCondition.BodyOp.CONTAINS, true, "CHECK THIS"));
/*  523 */     actions.add(new ZFilterAction.ZTagAction(this.mTag1.getName()));
/*  524 */     rules.add(new ZFilterRule("testCaseSensitiveComparison", true, false, conditions, actions));
/*  525 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*      */ 
/*  528 */     String subject = NAME_PREFIX + " testCaseSensitiveComparison1 check this";
/*  529 */     TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
/*  530 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  531 */     assertTrue("message should not have been tagged", (msg.getTagIds() == null) || (msg.getTagIds().isEmpty()));
/*      */     
/*      */ 
/*  534 */     subject = NAME_PREFIX + " testCaseSensitiveComparison2 CHECK THIS";
/*  535 */     TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
/*  536 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  537 */     assertNotNull("message should have been tagged", msg.getTagIds());
/*  538 */     Set<String> tagIds = new HashSet();
/*  539 */     tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
/*  540 */     assertTrue("message should have been tagged with tag1", tagIds.contains(this.mTag1.getId()));
/*      */     
/*      */ 
/*  543 */     subject = NAME_PREFIX + " testCaseSensitiveComparison3";
/*  544 */     String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withBody("Hi check this").create();
/*  545 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
/*  546 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  547 */     assertTrue("message should not have been tagged", (msg.getTagIds() == null) || (msg.getTagIds().isEmpty()));
/*      */     
/*      */ 
/*  550 */     subject = NAME_PREFIX + " testCaseSensitiveComparison4";
/*  551 */     content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withBody("Hi CHECK THIS").create();
/*  552 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
/*  553 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  554 */     assertNotNull("message should have been tagged", msg.getTagIds());
/*  555 */     tagIds = new HashSet();
/*  556 */     tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
/*  557 */     assertTrue("message should have been tagged with tag1", tagIds.contains(this.mTag1.getId()));
/*      */   }
/*      */   
/*      */   public void testCurrentTimeTest() throws Exception
/*      */   {
/*  562 */     TimeZone userTz = Util.getAccountTimeZone(TestUtil.getAccount(USER_NAME));
/*  563 */     Calendar calendar = Calendar.getInstance(userTz);
/*      */     
/*  565 */     calendar.add(12, 5);
/*      */     
/*  567 */     SimpleDateFormat format = new SimpleDateFormat("HHmm");
/*  568 */     format.setTimeZone(userTz);
/*  569 */     String timeStr = format.format(calendar.getTime());
/*      */     
/*  571 */     List<ZFilterRule> rules = new ArrayList();
/*  572 */     List<ZFilterCondition> conditions = new ArrayList();
/*  573 */     List<ZFilterAction> actions = new ArrayList();
/*      */     
/*  575 */     conditions.add(new ZFilterCondition.ZCurrentTimeCondition(ZFilterCondition.DateOp.AFTER, timeStr));
/*  576 */     actions.add(new ZFilterAction.ZTagAction(this.mTag1.getName()));
/*  577 */     rules.add(new ZFilterRule("testCurrentTimeTest after", true, false, conditions, actions));
/*  578 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  580 */     String subject = NAME_PREFIX + " testCurrentTimeTest1";
/*  581 */     TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
/*  582 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  583 */     assertTrue("message should not have been tagged", (msg.getTagIds() == null) || (msg.getTagIds().isEmpty()));
/*      */     
/*  585 */     rules = new ArrayList();
/*  586 */     conditions = new ArrayList();
/*      */     
/*  588 */     conditions.add(new ZFilterCondition.ZCurrentTimeCondition(ZFilterCondition.DateOp.BEFORE, timeStr));
/*  589 */     rules.add(new ZFilterRule("testCurrentTimeTest before", true, false, conditions, actions));
/*  590 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  592 */     subject = NAME_PREFIX + " testCurrentTimeTest2";
/*  593 */     TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
/*  594 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  595 */     assertNotNull("message should have been tagged", msg.getTagIds());
/*  596 */     Set<String> tagIds = new HashSet();
/*  597 */     tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
/*  598 */     assertTrue("message should have been tagged with tag1", tagIds.contains(this.mTag1.getId()));
/*      */   }
/*      */   
/*      */   public void testCurrentDayOfWeekTest() throws Exception
/*      */   {
/*  603 */     TimeZone userTz = Util.getAccountTimeZone(TestUtil.getAccount(USER_NAME));
/*  604 */     Calendar calendar = Calendar.getInstance(userTz);
/*  605 */     int dayToday = calendar.get(7) - 1;
/*  606 */     int dayYesterday = dayToday == 0 ? 6 : dayToday - 1;
/*  607 */     int dayTomorrow = dayToday == 6 ? 0 : dayToday + 1;
/*      */     
/*  609 */     List<ZFilterRule> rules = new ArrayList();
/*  610 */     List<ZFilterCondition> conditions = new ArrayList();
/*  611 */     List<ZFilterAction> actions = new ArrayList();
/*      */     
/*  613 */     conditions.add(new ZFilterCondition.ZCurrentDayOfWeekCondition(ZFilterCondition.SimpleOp.IS, dayYesterday + "," + dayTomorrow));
/*  614 */     actions.add(new ZFilterAction.ZTagAction(this.mTag1.getName()));
/*  615 */     rules.add(new ZFilterRule("testCurrentDayOfWeekTest day not today", true, false, conditions, actions));
/*  616 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  618 */     String subject = NAME_PREFIX + " testCurrentDayOfWeekTest1";
/*  619 */     TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
/*  620 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  621 */     assertTrue("message should not have been tagged", (msg.getTagIds() == null) || (msg.getTagIds().isEmpty()));
/*      */     
/*  623 */     rules = new ArrayList();
/*  624 */     conditions = new ArrayList();
/*      */     
/*  626 */     conditions.add(new ZFilterCondition.ZCurrentDayOfWeekCondition(ZFilterCondition.SimpleOp.IS, Integer.toString(dayToday)));
/*  627 */     rules.add(new ZFilterRule("testCurrentDayOfWeekTest today", true, false, conditions, actions));
/*  628 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  630 */     subject = NAME_PREFIX + " testCurrentDayOfWeekTest2";
/*  631 */     TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
/*  632 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  633 */     assertNotNull("message should have been tagged", msg.getTagIds());
/*  634 */     Set<String> tagIds = new HashSet();
/*  635 */     tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
/*  636 */     assertTrue("message should have been tagged with tag1", tagIds.contains(this.mTag1.getId()));
/*      */   }
/*      */   
/*      */   public void testAddressTest() throws Exception
/*      */   {
/*  641 */     List<ZFilterRule> rules = new ArrayList();
/*  642 */     List<ZFilterCondition> conditions = new ArrayList();
/*  643 */     List<ZFilterAction> actions = new ArrayList();
/*      */     
/*      */ 
/*  646 */     conditions.add(new ZFilterCondition.ZHeaderCondition("From", ZFilterCondition.HeaderOp.IS, "john.doe@example.com"));
/*  647 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/*  648 */     rules.add(new ZFilterRule("testAddressTest1", true, false, conditions, actions));
/*  649 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  651 */     String subject = NAME_PREFIX + " testAddressTest1";
/*  652 */     String mime = new MessageBuilder().withFrom("John Doe <john.doe@example.com>").withSubject(subject).create();
/*  653 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
/*  654 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  655 */     assertFalse("Unexpected message flag state", msg.isFlagged());
/*      */     
/*      */ 
/*  658 */     conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.all, ZFilterCondition.HeaderOp.IS, false, "john.doe@example.com"));
/*      */     
/*  660 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/*  661 */     rules.add(new ZFilterRule("testAddressTest2", true, false, conditions, actions));
/*  662 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  664 */     subject = NAME_PREFIX + " testAddressTest2";
/*  665 */     mime = new MessageBuilder().withFrom("John Doe <john.doe@example.com>").withSubject(subject).create();
/*  666 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
/*  667 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  668 */     assertTrue("Unexpected message flag state", msg.isFlagged());
/*      */   }
/*      */   
/*      */   public void testAddressTestPart() throws Exception
/*      */   {
/*  673 */     List<ZFilterRule> rules = new ArrayList();
/*  674 */     List<ZFilterCondition> conditions = new ArrayList();
/*  675 */     List<ZFilterAction> actions = new ArrayList();
/*      */     
/*      */ 
/*  678 */     conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.domain, ZFilterCondition.HeaderOp.IS, false, "example.com"));
/*      */     
/*  680 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/*  681 */     rules.add(new ZFilterRule("testAddressTestPart1", true, false, conditions, actions));
/*  682 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  684 */     String subject = NAME_PREFIX + " testAddressTestPart1";
/*  685 */     String mime = new MessageBuilder().withFrom("John Doe <JOHN.DOE@EXAMPLE.COM>").withSubject(subject).create();
/*  686 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
/*  687 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  688 */     assertTrue("Unexpected message flag state", msg.isFlagged());
/*      */     
/*      */ 
/*  691 */     conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.localpart, ZFilterCondition.HeaderOp.MATCHES, true, "j*doe"));
/*      */     
/*  693 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/*  694 */     rules.add(new ZFilterRule("testAddressTestPart2", true, false, conditions, actions));
/*  695 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  697 */     subject = NAME_PREFIX + " testAddressTestPart2";
/*  698 */     mime = new MessageBuilder().withFrom("John Doe <john.doe@example.com>").withSubject(subject).create();
/*  699 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
/*  700 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  701 */     assertTrue("Unexpected message flag state", msg.isFlagged());
/*      */   }
/*      */   
/*      */   public void testReplyAction() throws Exception
/*      */   {
/*  706 */     List<ZFilterRule> rules = new ArrayList();
/*  707 */     List<ZFilterCondition> conditions = new ArrayList();
/*  708 */     List<ZFilterAction> actions = new ArrayList();
/*  709 */     conditions.add(new ZFilterCondition.ZTrueCondition());
/*  710 */     actions.add(new ZFilterAction.ZReplyAction("Hi ${FROM}, Your message was: '${BODY}'. Thanks!"));
/*  711 */     rules.add(new ZFilterRule("testReplyAction", true, false, conditions, actions));
/*  712 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  714 */     String subject = NAME_PREFIX + " testReplyAction";
/*  715 */     String body = "Hi, How r u?";
/*  716 */     String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withSubject(subject).withBody(body).create();
/*      */     
/*  718 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
/*      */     
/*  720 */     TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*      */     
/*  722 */     ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"Re: " + subject + "\"");
/*      */     
/*  724 */     ZMessage.ZMimePart mimeStructure = zMessage.getMimeStructure();
/*  725 */     String bodyContent = mimeStructure.getContent();
/*  726 */     assertTrue("template vars should be replaced", (!bodyContent.contains("${FROM}")) && (!bodyContent.contains("${BODY}")));
/*      */     
/*  728 */     assertTrue((bodyContent.contains(TestUtil.getAddress(REMOTE_USER_NAME))) && (bodyContent.contains(body)));
/*      */     
/*      */ 
/*  731 */     assertTrue((!mimeStructure.getContentType().contains("charset")) || (mimeStructure.getContentType().contains("us-ascii")));
/*      */   }
/*      */   
/*      */   public void testNotifyAction()
/*      */     throws Exception
/*      */   {
/*  737 */     List<ZFilterRule> rules = new ArrayList();
/*  738 */     List<ZFilterCondition> conditions = new ArrayList();
/*  739 */     List<ZFilterAction> actions = new ArrayList();
/*  740 */     conditions.add(new ZFilterCondition.ZTrueCondition());
/*      */     
/*  742 */     actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), "${SUBJECT}", "From: ${FROM}, Message: ${BODY}"));
/*      */     
/*  744 */     rules.add(new ZFilterRule("testNotifyAction", true, false, conditions, actions));
/*  745 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  747 */     String subject = NAME_PREFIX + " testNotifyAction";
/*  748 */     String body = "Hi, How r u?";
/*  749 */     String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withSubject(subject).withBody(body).create();
/*      */     
/*  751 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
/*      */     
/*  753 */     TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*      */     
/*  755 */     ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"" + subject + "\"");
/*      */     
/*  757 */     ZMessage.ZMimePart mimeStructure = zMessage.getMimeStructure();
/*  758 */     String bodyContent = mimeStructure.getContent();
/*  759 */     assertTrue("template vars should be replaced", (!bodyContent.contains("${FROM}")) && (!bodyContent.contains("${BODY}")));
/*      */     
/*  761 */     assertTrue((bodyContent.contains(TestUtil.getAddress(REMOTE_USER_NAME))) && (bodyContent.contains(body)));
/*      */     
/*      */ 
/*  764 */     assertTrue((!mimeStructure.getContentType().contains("charset")) || (mimeStructure.getContentType().contains("us-ascii")));
/*      */   }
/*      */   
/*      */   public void testNotifyActionUseOrigHeaders()
/*      */     throws Exception
/*      */   {
/*  770 */     List<ZFilterRule> rules = new ArrayList();
/*  771 */     List<ZFilterCondition> conditions = new ArrayList();
/*  772 */     List<ZFilterAction> actions = new ArrayList();
/*  773 */     conditions.add(new ZFilterCondition.ZTrueCondition());
/*      */     
/*      */ 
/*  776 */     actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), null, "${BODY}", -1, "From,To,Cc,Subject"));
/*      */     
/*  778 */     rules.add(new ZFilterRule("testNotifyActionUseOrigHeaders", true, false, conditions, actions));
/*  779 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  781 */     String subject = NAME_PREFIX + " testNotifyActionUseOrigHeaders";
/*  782 */     String body = "Hi, How r u?";
/*  783 */     String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withToRecipient(USER_NAME).withCcRecipient(USER_NAME).withSubject(subject).withBody(body).create();
/*      */     
/*      */ 
/*  786 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
/*      */     
/*  788 */     ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"" + subject + "\"");
/*      */     
/*      */ 
/*  791 */     boolean checkedFrom = false;boolean checkedTo = false;boolean checkedCc = false;
/*  792 */     List<ZEmailAddress> msgAddrs = zMessage.getEmailAddresses();
/*  793 */     for (ZEmailAddress addr : msgAddrs) {
/*  794 */       if ("f".equals(addr.getType())) {
/*  795 */         assertEquals(TestUtil.addDomainIfNecessary(REMOTE_USER_NAME), addr.getAddress());
/*  796 */         if (!checkedFrom) {
/*  797 */           checkedFrom = true;
/*      */         } else {
/*  799 */           fail("multiple From addresses");
/*      */         }
/*      */       }
/*  802 */       if ("t".equals(addr.getType())) {
/*  803 */         assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
/*  804 */         if (!checkedTo) {
/*  805 */           checkedTo = true;
/*      */         } else {
/*  807 */           fail("multiple To addresses");
/*      */         }
/*      */       }
/*  810 */       if ("c".equals(addr.getType())) {
/*  811 */         assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
/*  812 */         if (!checkedCc) {
/*  813 */           checkedCc = true;
/*      */         } else {
/*  815 */           fail("multiple Cc addresses");
/*      */         }
/*      */       }
/*      */     }
/*  819 */     assertEquals(subject, zMessage.getSubject());
/*      */   }
/*      */   
/*      */   public void testNotifyActionCopyAllOrigHeaders() throws Exception
/*      */   {
/*  824 */     List<ZFilterRule> rules = new ArrayList();
/*  825 */     List<ZFilterCondition> conditions = new ArrayList();
/*  826 */     List<ZFilterAction> actions = new ArrayList();
/*  827 */     conditions.add(new ZFilterCondition.ZTrueCondition());
/*      */     
/*      */ 
/*  830 */     actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), null, "${BODY}", -1, "*"));
/*      */     
/*  832 */     rules.add(new ZFilterRule("testNotifyActionCopyAllOrigHeaders", true, false, conditions, actions));
/*  833 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  835 */     String subject = NAME_PREFIX + " testNotifyActionCopyAllOrigHeaders";
/*  836 */     String body = "Hi, How r u?";
/*  837 */     String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withToRecipient(USER_NAME).withCcRecipient(USER_NAME).withSubject(subject).withBody(body).create();
/*      */     
/*      */ 
/*  840 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
/*      */     
/*  842 */     ZMailbox zMailbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
/*  843 */     ZMessage zMessage = TestUtil.waitForMessage(zMailbox, "in:inbox subject:\"" + subject + "\"");
/*  844 */     String content = TestUtil.getContent(zMailbox, zMessage.getId());
/*      */     
/*  846 */     assertTrue(content.contains("From: " + REMOTE_USER_NAME));
/*  847 */     assertTrue(content.contains("To: " + USER_NAME));
/*  848 */     assertTrue(content.contains("Cc: " + USER_NAME));
/*  849 */     assertTrue(content.contains("Subject: " + subject));
/*      */   }
/*      */   
/*      */   public void testNotifyWithDiscard() throws Exception
/*      */   {
/*  854 */     List<ZFilterRule> rules = new ArrayList();
/*  855 */     List<ZFilterCondition> conditions = new ArrayList();
/*  856 */     List<ZFilterAction> actions = new ArrayList();
/*  857 */     conditions.add(new ZFilterCondition.ZTrueCondition());
/*      */     
/*  859 */     actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), "${SUBJECT}", "From: ${FROM}, Message: ${BODY}"));
/*      */     
/*      */ 
/*  862 */     actions.add(new ZFilterAction.ZDiscardAction());
/*  863 */     rules.add(new ZFilterRule("testNotifyWithDiscard", true, false, conditions, actions));
/*  864 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  866 */     String subject = NAME_PREFIX + " testNotifyWithDiscard";
/*  867 */     String body = "Hi, How r u?";
/*  868 */     String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withSubject(subject).withBody(body).create();
/*      */     
/*  870 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
/*      */     
/*      */ 
/*  873 */     List<ZMessage> msgs = TestUtil.search(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*  874 */     assertTrue("original message should not have been filed", msgs.isEmpty());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testMultipleMultilineText()
/*      */     throws Exception
/*      */   {
/*  886 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*  888 */     List<ZFilterCondition> conditions = new ArrayList();
/*  889 */     List<ZFilterAction> actions = new ArrayList();
/*  890 */     conditions.add(new ZFilterCondition.ZTrueCondition());
/*  891 */     String notifyMsg1 = "From: ${FROM}\nMessage: ${BODY}\n";
/*  892 */     actions.add(new ZFilterAction.ZNotifyAction("abc@xyz.com", "${SUBJECT}", notifyMsg1));
/*  893 */     String notifyMsg2 = "you've got mail";
/*  894 */     actions.add(new ZFilterAction.ZNotifyAction("abc@xyz.com", "subject", notifyMsg2));
/*  895 */     rules.add(new ZFilterRule("testMultipleMultilineText 1", true, false, conditions, actions));
/*      */     
/*  897 */     conditions = new ArrayList();
/*  898 */     actions = new ArrayList();
/*  899 */     conditions.add(new ZFilterCondition.ZTrueCondition());
/*  900 */     String replyMsg = "Replying to:\n${BODY}";
/*  901 */     actions.add(new ZFilterAction.ZReplyAction(replyMsg));
/*  902 */     rules.add(new ZFilterRule("testMultipleMultilineText 2", true, false, conditions, actions));
/*      */     
/*  904 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*  906 */     rules = this.mMbox.getIncomingFilterRules().getRules();
/*  907 */     assertEquals("There should be 2 rules", rules.size(), 2);
/*  908 */     assertEquals("Rule 1 should have 2 actions", ((ZFilterRule)rules.get(0)).getActions().size(), 2);
/*  909 */     assertEquals(((ZFilterAction.ZNotifyAction)((ZFilterRule)rules.get(0)).getActions().get(0)).getBodyTemplate(), notifyMsg1);
/*  910 */     assertEquals(((ZFilterAction.ZNotifyAction)((ZFilterRule)rules.get(0)).getActions().get(1)).getBodyTemplate(), notifyMsg2);
/*  911 */     assertEquals("Rule 2 should have 1 action", ((ZFilterRule)rules.get(1)).getActions().size(), 1);
/*  912 */     assertEquals(((ZFilterAction.ZReplyAction)((ZFilterRule)rules.get(1)).getActions().get(0)).getBodyTemplate(), replyMsg);
/*      */   }
/*      */   
/*      */   public void testMarkRead() throws Exception
/*      */   {
/*  917 */     String folderName = NAME_PREFIX + " testMarkRead";
/*      */     
/*      */ 
/*  920 */     List<ZFilterRule> rules = new ArrayList();
/*  921 */     List<ZFilterCondition> conditions = new ArrayList();
/*  922 */     List<ZFilterAction> actions = new ArrayList();
/*  923 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "testMarkRead"));
/*  924 */     actions.add(new ZFilterAction.ZFileIntoAction(folderName));
/*  925 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.READ));
/*  926 */     rules.add(new ZFilterRule("testMarkRead", true, false, conditions, actions));
/*  927 */     saveIncomingRules(this.mMbox, new ZFilterRules(rules));
/*      */     
/*      */ 
/*  930 */     String address = TestUtil.getAddress(USER_NAME);
/*  931 */     String subject = NAME_PREFIX + " testMarkRead";
/*  932 */     TestUtil.addMessageLmtp(subject, address, address);
/*      */     
/*      */ 
/*  935 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:\"" + folderName + "\" subject:\"" + subject + "\"");
/*  936 */     String flags = msg.getFlags();
/*  937 */     assertTrue("Unexpected flags: " + flags, (flags == null) || (flags.indexOf(ZItem.Flag.unread.getFlagChar()) < 0));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testHeaderFolding()
/*      */     throws Exception
/*      */   {
/*  947 */     List<ZFilterCondition> conditions = new ArrayList();
/*  948 */     List<ZFilterAction> actions = new ArrayList();
/*  949 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*      */ 
/*  952 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "a b c"));
/*  953 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/*  954 */     rules.add(new ZFilterRule("testHeaderFolding", true, false, conditions, actions));
/*      */     
/*  956 */     ZFilterRules zRules = new ZFilterRules(rules);
/*  957 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/*  960 */     String address = TestUtil.getAddress(USER_NAME);
/*  961 */     String subject = NAME_PREFIX + " a b\r\n c";
/*  962 */     TestUtil.addMessageLmtp(subject, address, address);
/*  963 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"a b c\"");
/*  964 */     assertTrue("Message was not flagged", msg.isFlagged());
/*      */   }
/*      */   
/*      */   public void testInvite() throws Exception
/*      */   {
/*  969 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/*      */     
/*      */ 
/*  972 */     String prefix = NAME_PREFIX + " testInvite ";
/*      */     
/*  974 */     ZTag tagNoMethod = mbox.createTag(prefix + "no method", null);
/*  975 */     ZTag tagAnyReply = mbox.createTag(prefix + "any reply", null);
/*  976 */     ZTag tagAnyRequest = mbox.createTag(prefix + "any request", null);
/*  977 */     ZTag tagRequestOrCancel = mbox.createTag(prefix + "request or cancel", null);
/*  978 */     ZTag tagReply = mbox.createTag(prefix + "reply", null);
/*      */     
/*      */ 
/*  981 */     List<ZFilterRule> rules = new ArrayList();
/*  982 */     ZFilterCondition condition = new ZFilterCondition.ZInviteCondition(true);
/*  983 */     ZFilterAction action = new ZFilterAction.ZTagAction(tagNoMethod.getName());
/*  984 */     rules.add(createRule("testInvite - no method", condition, action));
/*      */     
/*  986 */     condition = new ZFilterCondition.ZInviteCondition(true, "anyreply");
/*  987 */     action = new ZFilterAction.ZTagAction(tagAnyReply.getName());
/*  988 */     rules.add(createRule("testInvite - any reply", condition, action));
/*      */     
/*  990 */     condition = new ZFilterCondition.ZInviteCondition(true, "anyrequest");
/*  991 */     action = new ZFilterAction.ZTagAction(tagAnyRequest.getName());
/*  992 */     rules.add(createRule("testInvite - any request", condition, action));
/*      */     
/*  994 */     condition = new ZFilterCondition.ZInviteCondition(true, Arrays.asList(new String[] { "request", "cancel" }));
/*  995 */     action = new ZFilterAction.ZTagAction(tagRequestOrCancel.getName());
/*  996 */     rules.add(createRule("testInvite - request or cancel", condition, action));
/*      */     
/*  998 */     condition = new ZFilterCondition.ZInviteCondition(true, "reply");
/*  999 */     action = new ZFilterAction.ZTagAction(tagReply.getName());
/* 1000 */     rules.add(createRule("testInvite - reply", condition, action));
/*      */     
/* 1002 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1003 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/* 1006 */     ZMailbox organizer = TestUtil.getZMailbox(REMOTE_USER_NAME);
/* 1007 */     String subject = NAME_PREFIX + " testInvite request 1";
/* 1008 */     Date startDate = new Date(System.currentTimeMillis() + 86400000L);
/* 1009 */     Date endDate = new Date(startDate.getTime() + 3600000L);
/* 1010 */     TestUtil.createAppointment(organizer, subject, mbox.getName(), startDate, endDate);
/*      */     
/*      */ 
/* 1013 */     ZMessage msg = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 1014 */     Set<String> tagIds = getTagIds(msg);
/* 1015 */     assertTrue(tagIds.contains(tagNoMethod.getId()));
/* 1016 */     assertFalse(tagIds.contains(tagAnyReply.getId()));
/* 1017 */     assertTrue(tagIds.contains(tagAnyRequest.getId()));
/* 1018 */     assertTrue(tagIds.contains(tagRequestOrCancel.getId()));
/* 1019 */     assertFalse(tagIds.contains(tagReply.getId()));
/*      */     
/*      */ 
/*      */ 
/* 1023 */     organizer = TestUtil.getZMailbox(USER_NAME);
/* 1024 */     mbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
/* 1025 */     subject = NAME_PREFIX + " testInvite request 2";
/* 1026 */     startDate = new Date(startDate.getTime() + 86400000L);
/* 1027 */     endDate = new Date(endDate.getTime() + 86400000L);
/* 1028 */     TestUtil.createAppointment(organizer, subject, mbox.getName(), startDate, endDate);
/*      */     
/*      */ 
/* 1031 */     msg = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 1032 */     subject = NAME_PREFIX + " testInvite reply";
/* 1033 */     TestUtil.sendInviteReply(mbox, msg.getId(), organizer.getName(), subject, ZMailbox.ReplyVerb.ACCEPT);
/* 1034 */     msg = TestUtil.waitForMessage(organizer, "in:inbox subject:\"" + subject + "\"");
/*      */     
/*      */ 
/* 1037 */     tagIds = getTagIds(msg);
/* 1038 */     assertTrue(tagIds.contains(tagNoMethod.getId()));
/* 1039 */     assertTrue(tagIds.contains(tagAnyReply.getId()));
/* 1040 */     assertFalse(tagIds.contains(tagAnyRequest.getId()));
/* 1041 */     assertFalse(tagIds.contains(tagRequestOrCancel.getId()));
/* 1042 */     assertTrue(tagIds.contains(tagReply.getId()));
/*      */   }
/*      */   
/*      */   private ZFilterRule createRule(String name, ZFilterCondition condition, ZFilterAction action) {
/* 1046 */     return new ZFilterRule(name, true, false, Arrays.asList(new ZFilterCondition[] { condition }), Arrays.asList(new ZFilterAction[] { action }));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testManyAsterisks()
/*      */     throws Exception
/*      */   {
/* 1054 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1055 */     List<ZFilterAction> actions = new ArrayList();
/* 1056 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/* 1058 */     ZFilterCondition condition = new ZFilterCondition.ZHeaderCondition("from", ZFilterCondition.HeaderOp.MATCHES, "*****address@yahoo.com");
/*      */     
/* 1060 */     ZFilterAction action = new ZFilterAction.ZKeepAction();
/* 1061 */     conditions.add(condition);
/* 1062 */     actions.add(action);
/* 1063 */     rules.add(new ZFilterRule("test many asterisks", true, false, conditions, actions));
/*      */     
/* 1065 */     ZFilterRules zRules = new ZFilterRules(rules);
/*      */     try {
/* 1067 */       this.mMbox.saveIncomingFilterRules(zRules);
/* 1068 */       fail("Saving filter rules with quotes should not have succeeded");
/*      */     } catch (SoapFaultException e) {
/* 1070 */       assertTrue("Unexpected exception: " + e, e.getMessage().contains("four asterisks"));
/*      */     }
/*      */   }
/*      */   
/*      */   public void testDateFiltering()
/*      */     throws Exception
/*      */   {
/* 1077 */     ZTag tagBeforeTomorrow = this.mMbox.createTag(NAME_PREFIX + " before tomorrow", null);
/* 1078 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1079 */     List<ZFilterAction> actions = new ArrayList();
/* 1080 */     List<ZFilterRule> rules = new ArrayList();
/* 1081 */     conditions.add(new ZFilterCondition.ZDateCondition(ZFilterCondition.DateOp.BEFORE, new Date(System.currentTimeMillis() + 86400000L)));
/* 1082 */     actions.add(new ZFilterAction.ZTagAction(tagBeforeTomorrow.getName()));
/* 1083 */     rules.add(new ZFilterRule("before tomorrow", true, false, conditions, actions));
/*      */     
/*      */ 
/* 1086 */     ZTag tagAfterYesterday = this.mMbox.createTag(NAME_PREFIX + " after yesterday", null);
/* 1087 */     conditions = new ArrayList();
/* 1088 */     actions = new ArrayList();
/* 1089 */     conditions.add(new ZFilterCondition.ZDateCondition(ZFilterCondition.DateOp.AFTER, new Date(System.currentTimeMillis() - 86400000L)));
/* 1090 */     actions.add(new ZFilterAction.ZTagAction(tagAfterYesterday.getName()));
/* 1091 */     rules.add(new ZFilterRule("after yesterday", true, false, conditions, actions));
/*      */     
/*      */ 
/* 1094 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1095 */     this.mMbox.saveIncomingFilterRules(zRules);
/*      */     
/*      */ 
/* 1098 */     String[] recipients = { USER_NAME };
/* 1099 */     String subject = NAME_PREFIX + " testDateFiltering old";
/* 1100 */     String content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, new Date(System.currentTimeMillis() - 172800000L));
/*      */     
/* 1102 */     TestUtil.addMessageLmtp(recipients, USER_NAME, content);
/* 1103 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/* 1104 */     ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 1105 */     Set<String> tagIds = getTagIds(msg);
/* 1106 */     assertEquals(1, tagIds.size());
/* 1107 */     assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
/*      */     
/*      */ 
/* 1110 */     subject = NAME_PREFIX + " testDateFiltering current";
/* 1111 */     content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
/* 1112 */     TestUtil.addMessageLmtp(recipients, USER_NAME, content);
/* 1113 */     msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 1114 */     tagIds = getTagIds(msg);
/* 1115 */     assertEquals(2, tagIds.size());
/* 1116 */     assertTrue(tagIds.contains(tagAfterYesterday.getId()));
/* 1117 */     assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
/*      */     
/*      */ 
/* 1120 */     subject = NAME_PREFIX + " testDateFiltering future";
/* 1121 */     content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, new Date(System.currentTimeMillis() + 172800000L));
/*      */     
/* 1123 */     TestUtil.addMessageLmtp(recipients, USER_NAME, content);
/* 1124 */     msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 1125 */     tagIds = getTagIds(msg);
/* 1126 */     assertEquals(1, tagIds.size());
/* 1127 */     assertTrue(tagIds.contains(tagAfterYesterday.getId()));
/*      */     
/*      */ 
/* 1130 */     subject = NAME_PREFIX + " testDateFiltering no date header";
/* 1131 */     content = removeHeader(TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null), "Date");
/* 1132 */     TestUtil.addMessageLmtp(recipients, USER_NAME, content);
/* 1133 */     msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 1134 */     tagIds = getTagIds(msg);
/* 1135 */     assertEquals(2, tagIds.size());
/* 1136 */     assertTrue(tagIds.contains(tagAfterYesterday.getId()));
/* 1137 */     assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
/*      */   }
/*      */   
/*      */   private Set<String> getTagIds(ZMessage msg) {
/* 1141 */     Set<String> tagIds = new HashSet();
/* 1142 */     String tagIdString = msg.getTagIds();
/* 1143 */     if (tagIdString != null) {
/* 1144 */       tagIds.addAll(Arrays.asList(tagIdString.split(",")));
/*      */     }
/* 1146 */     return tagIds;
/*      */   }
/*      */   
/*      */   private String removeHeader(String content, String headerName) throws IOException
/*      */   {
/* 1151 */     StringBuilder buf = new StringBuilder();
/* 1152 */     BufferedReader reader = new BufferedReader(new StringReader(content));
/*      */     
/* 1154 */     String start = headerName + ": ";
/* 1155 */     String line; while ((line = reader.readLine()) != null) {
/* 1156 */       if (!line.startsWith(start)) {
/* 1157 */         buf.append(line).append("\r\n");
/*      */       }
/*      */     }
/* 1160 */     return buf.toString();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testHeaderMatches()
/*      */     throws Exception
/*      */   {
/* 1168 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1169 */     List<ZFilterAction> actions = new ArrayList();
/* 1170 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*      */ 
/* 1173 */     String pattern = NAME_PREFIX.substring(0, 4) + "*";
/* 1174 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.MATCHES, pattern));
/* 1175 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 1176 */     rules.add(new ZFilterRule("testHeaderMatches", true, false, conditions, actions));
/*      */     
/* 1178 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1179 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/* 1182 */     String address = TestUtil.getAddress(USER_NAME);
/* 1183 */     String subject = NAME_PREFIX + " testHeaderMatches";
/* 1184 */     TestUtil.addMessageLmtp(subject, address, address);
/* 1185 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:testHeaderMatches");
/* 1186 */     assertTrue("Message was not flagged", msg.isFlagged());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testBodyContains()
/*      */     throws Exception
/*      */   {
/* 1195 */     doBodyContainsTest("text version of the main body", true);
/* 1196 */     doBodyContainsTest("HTML version of the main body", true);
/* 1197 */     doBodyContainsTest("text attachment", false);
/* 1198 */     doBodyContainsTest("HTML attachment", false);
/* 1199 */     doBodyContainsTest("text version of the attached message body", true);
/* 1200 */     doBodyContainsTest("HTML version the attached message body", true);
/* 1201 */     doBodyContainsTest("body of a plain attached message", true);
/*      */     
/*      */ 
/* 1204 */     doBodyContainsTest("TeXt VeRsIoN", true);
/* 1205 */     doBodyContainsTest("hTmL vErSiOn", true);
/*      */     
/*      */ 
/* 1208 */     doBodyContainsTest("This is the text version of the main body of the message.", true);
/*      */     
/*      */ 
/* 1211 */     doBodyContainsTest("This is the text version of the main body of the message. This is the second line.", true);
/*      */   }
/*      */   
/*      */   private void doBodyContainsTest(String substring, boolean contains) throws Exception
/*      */   {
/* 1216 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1217 */     List<ZFilterAction> actions = new ArrayList();
/* 1218 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*      */ 
/* 1221 */     conditions.add(new ZFilterCondition.ZBodyCondition(ZFilterCondition.BodyOp.CONTAINS, substring));
/* 1222 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 1223 */     rules.add(new ZFilterRule("testBodyContains", true, false, conditions, actions));
/*      */     
/* 1225 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1226 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/* 1229 */     String address = TestUtil.getAddress(USER_NAME);
/* 1230 */     String msgContent = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/TestFilter-testBodyContains.msg")));
/*      */     
/* 1232 */     TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
/* 1233 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:testBodyContains");
/* 1234 */     assertEquals("Unexpected message flag state", contains, msg.isFlagged());
/* 1235 */     this.mMbox.deleteMessage(msg.getId());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testFullMatchAfterPartialMatch()
/*      */     throws Exception
/*      */   {
/* 1243 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1244 */     List<ZFilterAction> actions = new ArrayList();
/* 1245 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/* 1247 */     conditions.add(new ZFilterCondition.ZBodyCondition(ZFilterCondition.BodyOp.CONTAINS, "MatchThis"));
/* 1248 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 1249 */     rules.add(new ZFilterRule("testFullMatchAfterPartialMatch", true, false, conditions, actions));
/*      */     
/* 1251 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1252 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/* 1255 */     String subject = NAME_PREFIX + " testFullMatchAfterPartialMatch";
/* 1256 */     String content = new MessageBuilder().withSubject(subject).withBody("MatchMatchThis").create();
/* 1257 */     TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
/* 1258 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/* 1259 */     assertTrue("Unexpected message flag state", msg.isFlagged());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testSpecialCharInBody()
/*      */     throws Exception
/*      */   {
/* 1267 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1268 */     List<ZFilterAction> actions = new ArrayList();
/* 1269 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/* 1271 */     conditions.add(new ZFilterCondition.ZBodyCondition(ZFilterCondition.BodyOp.CONTAINS, "André"));
/* 1272 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 1273 */     rules.add(new ZFilterRule("testSpecialCharInBody", true, false, conditions, actions));
/*      */     
/* 1275 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1276 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/* 1279 */     String address = TestUtil.getAddress(USER_NAME);
/*      */     
/* 1281 */     String msgContent = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/TestFilter-testSpecialCharInBody.msg")));
/*      */     
/* 1283 */     TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
/* 1284 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:testSpecialCharInBody");
/* 1285 */     assertTrue("Unexpected message flag state", msg.isFlagged());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testRedirect()
/*      */     throws Exception
/*      */   {
/* 1294 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1295 */     List<ZFilterAction> actions = new ArrayList();
/* 1296 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*      */ 
/* 1299 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "testRedirect"));
/* 1300 */     actions.add(new ZFilterAction.ZRedirectAction(TestUtil.getAddress(REMOTE_USER_NAME)));
/* 1301 */     rules.add(new ZFilterRule("testRedirect", true, false, conditions, actions));
/*      */     
/* 1303 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1304 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/*      */ 
/* 1308 */     String from = "joebob@mycompany.com";
/* 1309 */     String subject = NAME_PREFIX + " testRedirect 1";
/* 1310 */     TestUtil.addMessageLmtp(subject, USER_NAME, from);
/*      */     
/*      */ 
/* 1313 */     List<ZMessage> messages = TestUtil.search(this.mMbox, "subject:\"" + subject + "\"");
/* 1314 */     assertEquals(0, messages.size());
/*      */     
/*      */ 
/* 1317 */     ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
/* 1318 */     ZMessage msg = TestUtil.waitForMessage(remoteMbox, "in:inbox subject:\"" + subject + "\"");
/* 1319 */     byte[] content = TestUtil.getContent(remoteMbox, msg.getId()).getBytes();
/* 1320 */     MimeMessage mimeMsg = new MimeMessage(new ByteArrayInputStream(content));
/* 1321 */     Account user1 = TestUtil.getAccount(USER_NAME);
/* 1322 */     assertEquals(user1.getName(), mimeMsg.getHeader("X-Zimbra-Forwarded"));
/* 1323 */     assertEquals(from, mimeMsg.getHeader("From"));
/*      */     
/*      */ 
/* 1326 */     int port = 6025;
/* 1327 */     DummySmtpServer smtp = startSmtpServer(port);
/* 1328 */     Server server = Provisioning.getInstance().getLocalServer();
/* 1329 */     server.setSmtpPort(port);
/* 1330 */     server.setMailRedirectSetEnvelopeSender(false);
/*      */     
/* 1332 */     TestUtil.addMessageLmtp(subject, USER_NAME, from);
/* 1333 */     assertEquals(from, smtp.getMailFrom());
/*      */     
/*      */ 
/* 1336 */     smtp = startSmtpServer(port);
/* 1337 */     server.setMailRedirectSetEnvelopeSender(true);
/* 1338 */     subject = NAME_PREFIX + " testRedirect 2";
/* 1339 */     TestUtil.addMessageLmtp(subject, USER_NAME, from);
/* 1340 */     String userAddress = Strings.nullToEmpty(TestUtil.getAddress(USER_NAME)).toLowerCase();
/*      */     
/* 1342 */     assertEquals("testRedirect 2 mail from", userAddress, smtp.getMailFrom());
/*      */     
/*      */ 
/* 1345 */     smtp = startSmtpServer(port);
/* 1346 */     subject = NAME_PREFIX + " testRedirect 3";
/* 1347 */     String msgContent = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
/* 1348 */     String[] recipients = { USER_NAME };
/* 1349 */     TestUtil.addMessageLmtp(recipients, null, msgContent);
/* 1350 */     assertTrue(smtp.getMailFrom(), StringUtil.isNullOrEmpty(smtp.getMailFrom()));
/*      */     
/*      */ 
/* 1353 */     smtp = startSmtpServer(port);
/* 1354 */     subject = NAME_PREFIX + " testRedirect 4";
/* 1355 */     msgContent = "Auto-Submitted: yes\r\n" + TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
/* 1356 */     TestUtil.addMessageLmtp(recipients, USER_NAME, msgContent);
/* 1357 */     assertTrue(smtp.getMailFrom(), StringUtil.isNullOrEmpty(smtp.getMailFrom()));
/*      */     
/*      */ 
/* 1360 */     smtp = startSmtpServer(port);
/* 1361 */     subject = NAME_PREFIX + " testRedirect 5";
/* 1362 */     msgContent = "Auto-Submitted: no\r\n" + TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
/* 1363 */     TestUtil.addMessageLmtp(recipients, USER_NAME, msgContent);
/* 1364 */     assertEquals("testRedirect 5 mail from", userAddress, smtp.getMailFrom());
/*      */     
/*      */ 
/* 1367 */     smtp = startSmtpServer(port);
/* 1368 */     subject = NAME_PREFIX + " testRedirect 6";
/* 1369 */     msgContent = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
/* 1370 */     msgContent = msgContent.replace("text/plain", "multipart/report");
/* 1371 */     TestUtil.addMessageLmtp(recipients, USER_NAME, msgContent);
/* 1372 */     assertTrue(smtp.getMailFrom(), StringUtil.isNullOrEmpty(smtp.getMailFrom()));
/*      */   }
/*      */   
/*      */   private DummySmtpServer startSmtpServer(int port) {
/* 1376 */     DummySmtpServer smtp = new DummySmtpServer(port);
/* 1377 */     Thread smtpServerThread = new Thread(smtp);
/* 1378 */     smtpServerThread.start();
/* 1379 */     return smtp;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testRedirectMailLoop()
/*      */     throws Exception
/*      */   {
/* 1387 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1388 */     List<ZFilterAction> actions = new ArrayList();
/* 1389 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*      */ 
/* 1392 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "testRedirectMailLoop"));
/* 1393 */     actions.add(new ZFilterAction.ZRedirectAction(TestUtil.getAddress(USER_NAME)));
/* 1394 */     rules.add(new ZFilterRule("testRedirectMailLoop", true, false, conditions, actions));
/*      */     
/* 1396 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1397 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/* 1400 */     String subject = NAME_PREFIX + " testRedirectMailLoop";
/* 1401 */     TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
/*      */     
/*      */ 
/* 1404 */     ZMessage msg = TestUtil.waitForMessage(this.mMbox, "subject:\"" + subject + "\"");
/* 1405 */     byte[] content = TestUtil.getContent(this.mMbox, msg.getId()).getBytes();
/* 1406 */     MimeMessage mimeMsg = new MimeMessage(new ByteArrayInputStream(content));
/* 1407 */     Account user1 = TestUtil.getAccount(USER_NAME);
/* 1408 */     assertEquals(user1.getName(), mimeMsg.getHeader("X-Zimbra-Forwarded"));
/*      */   }
/*      */   
/*      */   public void testAttachment() throws Exception
/*      */   {
/* 1413 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1414 */     List<ZFilterAction> actions = new ArrayList();
/* 1415 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*      */ 
/* 1418 */     ZTag tag1 = this.mMbox.createTag(NAME_PREFIX + " testAttachment1", null);
/* 1419 */     ZTag tag2 = this.mMbox.createTag(NAME_PREFIX + " testAttachment2", null);
/*      */     
/* 1421 */     conditions.add(new ZFilterCondition.ZAttachmentExistsCondition(true));
/* 1422 */     actions.add(new ZFilterAction.ZTagAction(tag1.getName()));
/* 1423 */     rules.add(new ZFilterRule("testAttachment1", true, false, conditions, actions));
/*      */     
/* 1425 */     conditions = new ArrayList();
/* 1426 */     actions = new ArrayList();
/* 1427 */     conditions.add(new ZFilterCondition.ZAttachmentExistsCondition(false));
/* 1428 */     actions.add(new ZFilterAction.ZTagAction(tag2.getName()));
/* 1429 */     rules.add(new ZFilterRule("testAttachment2", true, false, conditions, actions));
/*      */     
/* 1431 */     ZFilterRules zRules = new ZFilterRules(rules);
/* 1432 */     saveIncomingRules(this.mMbox, zRules);
/*      */     
/*      */ 
/* 1435 */     String address = TestUtil.getAddress(USER_NAME);
/* 1436 */     String subject = NAME_PREFIX + " testAttachment1";
/* 1437 */     String msgContent = new MessageBuilder().withSubject(subject).withAttachment("attach this", "attach.txt", "text/plain").create();
/* 1438 */     TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
/* 1439 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*      */     
/*      */ 
/* 1442 */     Set<String> tagIds = getTagIds(msg);
/* 1443 */     assertEquals(1, tagIds.size());
/* 1444 */     assertTrue(tagIds.contains(tag1.getId()));
/*      */     
/*      */ 
/* 1447 */     subject = NAME_PREFIX + " testAttachment2";
/* 1448 */     msgContent = new MessageBuilder().withSubject(subject).create();
/* 1449 */     TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
/* 1450 */     msg = TestUtil.getMessage(this.mMbox, "in:inbox subject:\"" + subject + "\"");
/*      */     
/*      */ 
/* 1453 */     tagIds = getTagIds(msg);
/* 1454 */     assertEquals(1, tagIds.size());
/* 1455 */     assertTrue(tagIds.contains(tag2.getId()));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void testParseSize()
/*      */     throws Exception
/*      */   {
/* 1463 */     assertEquals(10, FilterUtil.parseSize("10"));
/* 1464 */     assertEquals(10240, FilterUtil.parseSize("10k"));
/* 1465 */     assertEquals(10240, FilterUtil.parseSize("10K"));
/* 1466 */     assertEquals(10485760, FilterUtil.parseSize("10M"));
/* 1467 */     assertEquals(Integer.MIN_VALUE, FilterUtil.parseSize("10G"));
/*      */     try {
/* 1469 */       FilterUtil.parseSize("10Q");
/* 1470 */       fail("Should not have parsed bogus size value.");
/*      */     }
/*      */     catch (NumberFormatException e) {}
/*      */   }
/*      */   
/*      */ 
/*      */   private String normalize(String script)
/*      */     throws ParseException, ServiceException
/*      */   {
/* 1479 */     List<String> ruleNames = RuleManager.getRuleNames(script);
/* 1480 */     Node node = RuleManager.getSieveFactory().parse(new ByteArrayInputStream(script.getBytes()));
/*      */     
/*      */ 
/* 1483 */     SieveToSoap sieveToSoap = new SieveToSoap(ruleNames);
/* 1484 */     sieveToSoap.accept(node);
/* 1485 */     SoapToSieve soapToSieve = new SoapToSieve(sieveToSoap.toFilterRules());
/*      */     
/* 1487 */     return soapToSieve.getSieveScript();
/*      */   }
/*      */   
/*      */   public void testStripBracketsAndQuotes() throws Exception
/*      */   {
/* 1492 */     assertEquals(null, RuleRewriter.stripBracketsAndQuotes(null));
/* 1493 */     assertEquals("", RuleRewriter.stripBracketsAndQuotes(""));
/* 1494 */     assertEquals("x", RuleRewriter.stripBracketsAndQuotes("x"));
/* 1495 */     assertEquals("x", RuleRewriter.stripBracketsAndQuotes("[\"x\"]"));
/* 1496 */     assertEquals("x", RuleRewriter.stripBracketsAndQuotes("\"x\""));
/* 1497 */     assertEquals("x\"", RuleRewriter.stripBracketsAndQuotes("x\""));
/* 1498 */     assertEquals("[\"x\"", RuleRewriter.stripBracketsAndQuotes("[\"x\""));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void testPositiveAndNegative()
/*      */     throws Exception
/*      */   {
/* 1507 */     String script = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/bug46007.sieve")));
/* 1508 */     String normalized = normalize(script);
/* 1509 */     assertEquals(normalizeWhiteSpace(script), normalizeWhiteSpace(normalized));
/*      */   }
/*      */   
/*      */   private String normalizeWhiteSpace(String script) {
/* 1513 */     StringBuilder buf = new StringBuilder(script.length());
/* 1514 */     boolean inWhiteSpace = false;
/* 1515 */     for (int i = 0; i < script.length(); i++) {
/* 1516 */       String c = script.substring(i, i + 1);
/* 1517 */       if ((c.matches("\\s")) || (c.equals("\r")) || (c.equals("\n"))) {
/* 1518 */         if (!inWhiteSpace) {
/* 1519 */           buf.append(" ");
/* 1520 */           inWhiteSpace = true;
/*      */         }
/*      */       } else {
/* 1523 */         inWhiteSpace = false;
/* 1524 */         buf.append(c);
/*      */       }
/*      */     }
/* 1527 */     return buf.toString();
/*      */   }
/*      */   
/*      */   protected void tearDown() throws Exception
/*      */   {
/* 1532 */     this.mMbox.saveIncomingFilterRules(this.mOriginalIncomingRules);
/* 1533 */     this.mMbox.saveOutgoingFilterRules(this.mOriginalOutgoingRules);
/* 1534 */     TestUtil.setAccountAttr(USER_NAME, "zimbraSpamApplyUserFilters", this.mOriginalSpamApplyUserFilters);
/* 1535 */     TestUtil.setServerAttr("zimbraSmtpPort", this.mOriginalSmtpPort);
/* 1536 */     TestUtil.setServerAttr("zimbraMailRedirectSetEnvelopeSender", this.mOriginalSetEnvelopeSender);
/* 1537 */     cleanUp();
/*      */   }
/*      */   
/*      */   private void cleanUp() throws Exception
/*      */   {
/* 1542 */     TestUtil.deleteTestData(USER_NAME, NAME_PREFIX);
/* 1543 */     TestUtil.deleteTestData(REMOTE_USER_NAME, NAME_PREFIX);
/*      */     
/*      */ 
/*      */ 
/* 1547 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/* 1548 */     for (ZMessage msg : TestUtil.search(mbox, "cortes de luz")) {
/* 1549 */       mbox.deleteMessage(msg.getId());
/*      */     }
/*      */   }
/*      */   
/*      */   private ZFilterRules getTestOutgoingRules() throws Exception
/*      */   {
/* 1555 */     List<ZFilterRule> rules = new ArrayList();
/*      */     
/*      */ 
/* 1558 */     List<ZFilterCondition> conditions = new ArrayList();
/*      */     
/* 1560 */     List<ZFilterAction> actions = new ArrayList();
/* 1561 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "outgoing"));
/* 1562 */     actions.add(new ZFilterAction.ZFileIntoAction(FOLDER1_PATH));
/* 1563 */     actions.add(new ZFilterAction.ZTagAction(TAG1_NAME));
/* 1564 */     rules.add(new ZFilterRule("testOutgoingFilters1", true, false, conditions, actions));
/*      */     
/* 1566 */     return new ZFilterRules(rules);
/*      */   }
/*      */   
/*      */   private ZFilterRules getTestIncomingRules() throws Exception
/*      */   {
/* 1571 */     List<ZFilterRule> rules = new ArrayList();
/* 1572 */     List<ZFilterCondition> conditions = new ArrayList();
/* 1573 */     List<ZFilterAction> actions = new ArrayList();
/*      */     
/*      */ 
/* 1576 */     conditions = new ArrayList();
/* 1577 */     actions = new ArrayList();
/* 1578 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "folder1"));
/* 1579 */     actions.add(new ZFilterAction.ZFileIntoAction(FOLDER1_PATH));
/* 1580 */     actions.add(new ZFilterAction.ZTagAction(TAG1_NAME));
/* 1581 */     rules.add(new ZFilterRule("testMatchMultipleFilters1", true, false, conditions, actions));
/*      */     
/*      */ 
/* 1584 */     conditions = new ArrayList();
/* 1585 */     actions = new ArrayList();
/* 1586 */     conditions.add(new ZFilterCondition.ZHeaderCondition("from", ZFilterCondition.HeaderOp.CONTAINS, "multiplefilters"));
/* 1587 */     actions.add(new ZFilterAction.ZFileIntoAction(FOLDER2_PATH));
/* 1588 */     actions.add(new ZFilterAction.ZTagAction(TAG2_NAME));
/* 1589 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 1590 */     rules.add(new ZFilterRule("testMatchMultipleFilters2", true, false, conditions, actions));
/*      */     
/*      */ 
/* 1593 */     conditions = new ArrayList();
/* 1594 */     actions = new ArrayList();
/* 1595 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "bug5455"));
/* 1596 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 1597 */     actions.add(new ZFilterAction.ZFileIntoAction(FOLDER1_PATH));
/* 1598 */     actions.add(new ZFilterAction.ZTagAction(TAG1_NAME));
/* 1599 */     actions.add(new ZFilterAction.ZFileIntoAction(FOLDER2_PATH));
/* 1600 */     rules.add(new ZFilterRule("testBug5455", true, false, conditions, actions));
/*      */     
/*      */ 
/* 1603 */     conditions = new ArrayList();
/* 1604 */     actions = new ArrayList();
/* 1605 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "doDiscard"));
/* 1606 */     actions.add(new ZFilterAction.ZDiscardAction());
/* 1607 */     rules.add(new ZFilterRule("testDiscard", true, false, conditions, actions));
/*      */     
/*      */ 
/* 1610 */     conditions = new ArrayList();
/* 1611 */     actions = new ArrayList();
/* 1612 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "mountpointRoot"));
/* 1613 */     actions.add(new ZFilterAction.ZFileIntoAction("/" + MOUNTPOINT_FOLDER_NAME));
/* 1614 */     rules.add(new ZFilterRule("testMountpoint", true, false, conditions, actions));
/*      */     
/*      */ 
/* 1617 */     conditions = new ArrayList();
/* 1618 */     actions = new ArrayList();
/* 1619 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "mountpointSub"));
/* 1620 */     actions.add(new ZFilterAction.ZFileIntoAction(MOUNTPOINT_SUBFOLDER_PATH));
/* 1621 */     rules.add(new ZFilterRule("testMountpointSubfolder", true, false, conditions, actions));
/*      */     
/* 1623 */     return new ZFilterRules(rules);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private void saveIncomingRules(ZMailbox mbox, ZFilterRules rules)
/*      */     throws Exception
/*      */   {
/* 1631 */     mbox.saveIncomingFilterRules(rules);
/* 1632 */     ZFilterRules result = mbox.getIncomingFilterRules(true);
/* 1633 */     TestUtil.assertEquals(rules.dump(), result.dump());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private void saveOutgoingRules(ZMailbox mbox, ZFilterRules rules)
/*      */     throws Exception
/*      */   {
/* 1641 */     mbox.saveOutgoingFilterRules(rules);
/* 1642 */     ZFilterRules result = mbox.getOutgoingFilterRules(true);
/* 1643 */     TestUtil.assertEquals(rules.dump(), result.dump());
/*      */   }
/*      */   
/*      */   public static void main(String[] args) throws Exception
/*      */   {
/* 1648 */     TestUtil.cliSetup();
/* 1649 */     TestUtil.runTest(TestFilter.class);
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestFilter.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */